package xyz.icxl.android.architecture.ui


import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import xyz.icxl.android.architecture.R

/**
 * 文件描述：基础的弹窗
 *
 * 文件创建人：ChenXinLei
 *
 * 文件创建人联系方式：502616659(QQ)
 *
 * 创建时间：2020 年 06月 30 日
 *
 * 文件版本：v1.0
 *
 * 版本描述：创建文件
 */
abstract class BaseBottomSheetDialogFragment : BottomSheetDialogFragment() {

    abstract fun layoutId(): Int
    abstract fun doSomething(rootView: View)

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(layoutId(), container, false)
        doSomething(view)
        return view
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme)
    }

    /**
     * 展示全部布局
     */
    protected fun expansionLayout() {
        val baseDialog = dialog
        if (baseDialog is BottomSheetDialog) {
            val behavior: BottomSheetBehavior<*> = baseDialog.behavior
            behavior.state = BottomSheetBehavior.STATE_EXPANDED
        }
    }


    fun show(manager: FragmentManager) {
        super.show(manager, System.currentTimeMillis().toString())
    }
}